#ifndef MASTERTHREAD_H
#define MASTERTHREAD_H

#include <QMutex>
#include <QThread>
#include <QWaitCondition>
#include <QSerialPort>
#include <QTime>

//! [0]
class MasterThread : public QThread
{
    Q_OBJECT

public:
    explicit MasterThread(QObject *parent = nullptr);
    ~MasterThread();

    void transaction(const int devIndex,const QString &devName,const QString &portName,const QSerialPort::BaudRate baudrate, QSerialPort::DataBits databits, QSerialPort::Parity parity, QSerialPort::StopBits stopbits, int waitTimeout, const QString &request);
    //void threadQuit();

signals:
    void response2(const int devIndex,const QString &devName,const QString &res);
    void error(const QString &s);
    void timeout(const QString &s);

private:
    void run() override;
    int m_devIndex;
    QString m_devName;
    QString m_portName;
    QSerialPort::BaudRate m_baudrate;
    QSerialPort::DataBits m_databits;
    QSerialPort::Parity m_parity;
    QSerialPort::StopBits m_stopbits;
//    QQueue<QString> m_request;
    QString m_request;
    int m_waitTimeout = 0;
    QMutex m_mutex;
    QWaitCondition m_cond;
    bool m_quit = false;
};
//! [0]

#endif // MASTERTHREAD_H
